package net.xisberto.bustime;

import java.io.IOException;
import java.util.ArrayList;

import net.xisberto.bustime.control.SQLiteResourceDatabase;
import net.xisberto.bustime.model.Bus;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public abstract class BusListActivity extends CustomActivity implements OnItemClickListener {
	protected SQLiteResourceDatabase db;
	protected ArrayList<Bus> bus_list;
	protected int list_id = android.R.id.list;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		db = new SQLiteResourceDatabase(this);
		try {
			db.createDataBase();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	protected void populateList() {
		ListView list = (ListView) findViewById(list_id);
		BusAdapter adapter = new BusAdapter(this, android.R.layout.simple_list_item_2, bus_list);
		list.setAdapter(adapter);
		if (list.getCount() > 0) {
			findViewById(android.R.id.empty).setVisibility(View.GONE);
		} else {
			findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
		}
	}

}
